<template>
  <div class="cart-list">
    <scroll v-if="cartList.length > 0" class="content" ref="srcoll"> 
      <cart-list-item 
      v-for="(item, index) in cartList" 
      :product="item"
      :key="index"
      ></cart-list-item>
    </scroll>
    <div v-else class="content">
      <div class="item">
        <img src="~assets/img/tabbar/shopcart.svg">
        <div>购物车为空，赶紧去添加吧</div>
        <span class="nav" @click="nav">皮皮虾，我们走!</span>
      </div>
    </div>
  </div>
</template>

<script>
  import Scroll from 'components/common/scroll/Scroll'
  import CartListItem from './CartListItem'

  import { mapGetters } from 'vuex'

  export default {
    name: 'CartList',
    components: {
      Scroll,
      CartListItem,
    },
    //监听属性 类似于data概念
    computed: {
      ...mapGetters([
        'cartList'
      ])
    },
    methods: {
      nav() {
        this.$router.push('/home')
      }
    }
  }
</script>
<style scoped>
  .cart-list {
    height: calc(100% - 44px); 
  }

  .content {
    height: calc(100% - 95px);
    overflow: hidden;
    position: relative;
  }
  .item {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-style: italic;
    color: rgb(204, 180, 180);
    font-size: 0.8rem;
    text-align: center;
  }
  .item img {
    width: 50vw;
    height: auto;
    opacity: 0.2;
  }
  .nav {
    color: rgb(110, 216, 108);
    font-size: 1rem;
    border-bottom: 1px solid rgb(110, 216, 108);
    padding-bottom: 0.1rem;
  }
</style>